home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Level 0 Macintosh 29Sep94 / Definitions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  3.6 KB  |  100 lines  |  [TEXT/KAHL]

  1. /* Definitions.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    System Dependency Library for Building Portable Software               */
  5. /*    Macintosh Version                                                      */
  6. /*    Written by Thomas R. Lawrence, 1993 - 1994.                            */
  7. /*                                                                           */
  8. /*    This file is Public Domain; it may be used for any purpose whatsoever  */
  9. /*    without restriction.                                                   */
  10. /*                                                                           */
  11. /*    This package is distributed in the hope that it will be useful,        */
  12. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  13. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   */
  14. /*                                                                           */
  15. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  16. /*                                                                           */
  17. /*****************************************************************************/
  18.  
  19. #include "MiscInfo.h"
  20. #include "Definitions.h"
  21. #include "Audit.h"
  22. #include "Debug.h"
  23.  
  24. #ifdef THINK_C
  25.     #pragma options(pack_enums)
  26. #endif
  27. #include <Memory.h>
  28. #ifdef THINK_C
  29.     #pragma options(!pack_enums)
  30. #endif
  31.  
  32.  
  33. /* move data.  The data can be overlapping. */
  34. void                MoveData(char* Source, char* Destination, long NumBytes)
  35.     {
  36. #if DEBUG && !defined(__cplusplus) && defined(THINK_C)
  37.         Zone*                Zone;
  38.         char*                ZoneBeginning;
  39.         char*                ZoneEnd;
  40.  
  41.         /* a handy error check:  make sure the source and destination are actually */
  42.         /* in the bounds of the heap.  (debugging suppresses allocation of data */
  43.         /* from temporary memory) */
  44.         Zone = GetZone();
  45.         ZoneBeginning = (char*)&(Zone->heapData);
  46.         asm
  47.             {
  48.                 move.l a5,ZoneEnd
  49.             }
  50.         if ((ZoneBeginning > (char*)Source)
  51.             || (ZoneEnd <= (char*)Source + NumBytes)
  52.             || (ZoneBeginning > (char*)Destination)
  53.             || (ZoneEnd <= (char*)Destination + NumBytes))
  54.             {
  55.                 APRINT(("!MoveData %r->%r(+%l) [%r..%r]",Source,Destination,NumBytes,
  56.                     ZoneBeginning,ZoneEnd));
  57.                 PRERR(ForceAbort,"MoveData:  source or destination beyond heap limits!");
  58.             }
  59. #endif
  60.  
  61.         ERROR(NumBytes < 0,PRERR(ForceAbort,
  62.             "MoveData:  Request to move negative number of bytes"));
  63.         BlockMove(Source,Destination,NumBytes);
  64.     }
  65.  
  66.  
  67. /* copy data.  the regions can NOT be overlapping and an error will result */
  68. /* if they are */
  69. void                CopyData(char* Source, char* Destination, long NumBytes)
  70.     {
  71. #if DEBUG && !defined(__cplusplus) && defined(THINK_C)
  72.         Zone*                Zone;
  73.         char*                ZoneBeginning;
  74.         char*                ZoneEnd;
  75.  
  76.         Zone = GetZone();
  77.         ZoneBeginning = (char*)&(Zone->heapData);
  78.         asm
  79.             {
  80.                 move.l a5,ZoneEnd
  81.             }
  82.         if ((ZoneBeginning > (char*)Source)
  83.             || (ZoneEnd <= (char*)Source + NumBytes)
  84.             || (ZoneBeginning > (char*)Destination)
  85.             || (ZoneEnd <= (char*)Destination + NumBytes))
  86.             {
  87.                 APRINT(("!CopyData %r->%r(+%l) [%r..%r]",Source,Destination,NumBytes,
  88.                     ZoneBeginning,ZoneEnd));
  89.                 PRERR(ForceAbort,"CopyData:  source or destination beyond heap limits!");
  90.             }
  91. #endif
  92.  
  93.         ERROR(NumBytes < 0,PRERR(ForceAbort,
  94.             "CopyData:  Request to move negative number of bytes"));
  95.         ERROR(((Source <= Destination) && (Source + NumBytes > Destination))
  96.             || ((Destination <= Source) && (Destination + NumBytes > Source)),
  97.             PRERR(ForceAbort,"CopyData:  Request to copy overlapping blocks"));
  98.         BlockMove(Source,Destination,NumBytes);
  99.     }
  100.